<?php 
	include 'common.php';
	$a = $_GET['a'];

	switch($a){
		case 'add':
			$id = $_POST['id'];
			$name = $_POST['name'];
			$image = $_POST['image'];
			$price = $_POST['price'];
			$num = $_POST['num'];
			$store = $_POST['store'];
			if($num > $store) echo jump('抱歉！库存不足',3,$_SERVER['HTTP_REFERER']);
			if($num < 1) $num =1;
			if(!empty($_SESSION['cart'][$id])) $num += $_SESSION['cart'][$id]['num'];
			
			$_SESSION['cart'][$id] = array(
			'num' => $num,
			'price' => $price,
			'image' => $image,
			'name' => $name,
			'store' => $store
			);

			header('location:shoppingcar.php');
			break;
			
		case 'del':
			$id = $_GET['id'];
			unset($_SESSION['cart'][$id]);
    		header('location:shoppingcar.php');
			break;
			
		case 'mf':
			$id = $_GET['id'];
			$value = $_GET['value'];
			if($value < 1) $value = 1;
			if($value > $_SESSION['cart'][$id]['store']) $value = $_SESSION['cart'][$id]['store'];
			$_SESSION['cart'][$id]['num'] = $value;
    		header('location:shoppingcar.php');
			break;
		
		case 'emp':
			unset($_SESSION['cart']);
    		header('location:shoppingcar.php');
			break;
			
		case 'rec':
			//获取数据
			$user_id = $_SESSION['home']['id'];
			$name = $_POST['name'];
			$phone = $_POST['tel'];
			$address = $_POST['address'];

			//更新order_receiver表
			$sql = "insert into ".PRE."order_receiver(user_id,name,phone,address) values('{$user_id}','{$name}','{$phone}','{$address}')";
			mysql_query($sql);
			header('Location:order_inf.php');
			break;
			
		case 'recdel':
			$id = $_GET['id'];
			$sql = "delete from ".PRE."order_receiver where id='{$id}'";
			mysql_query($sql);
			header('Location:'.$_SERVER['HTTP_REFERER']);
			break;
	}
